<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="../js/jq-1.12.4.js"></script>
    <link rel="stylesheet" href="../css/post.css">
    <link rel="stylesheet" href="../css/common.css">
</head>

<body>
    <div class="app">
        <div class="login">
            <input type="text" id="username" placeholder="用户名">
            <input type="text" id="password" placeholder="密码">
            <input type="button" id="submit" value="登录">
        </div>

    </div>
    <div class="msg"></div>
</body>
<!-- js model 逻辑-->
<script>
    $(function () {
        $("#submit").click(function () {
            //登录前要验证，此处先省略
            //准备参数
            let url = 'http://192.168.102.55:3000/users/login'
            //data是对象 参数是固定写法
            let data = {
                userName: $("#username").val(),
                userPassword: $("#password").val()
            }

            //模拟登录请求
            $.post(url, data, function (res) {
      
                console.log(res)
                let arr = res
                //用长度判断内容
                if (arr.length) {
                    $(".msg").empty().html("登录成功！")
                } else {
                    $(".msg").empty().html("错误的用户名或密码！")
                }
            })
        })
    })

</script>

</html>